package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.CarPinPaParam
import com.cheyun.netsalev3.bean.CarXiParam
import com.cheyun.netsalev3.bean.ChannelListParam
import com.cheyun.netsalev3.bean.X
import com.cheyun.netsalev3.bean.dms.Product
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlin.reflect.KFunction1
import kotlin.reflect.KFunction2

class ChooseCarRepository {
    //获取品牌
    fun getBran(kFunction0: KFunction1<@ParameterName(name = "list") ArrayList<CarPinPaParam>, Unit>) {
        ApiClient.getInstance().getBrand("1", "")
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<ArrayList<CarPinPaParam>>>() {
                    override fun onSuccess(t: BaseResp<ArrayList<CarPinPaParam>>) {
                        t.data?.apply {
                            kFunction0(this)
                        }
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }

    /**
     * 获取车型 车系 类型 1-品牌，3-车系，5-车型
     */
    fun getCar(type: String, pid: String, kFunction1: KFunction2<@ParameterName(name = "type") String, @ParameterName(name = "list") List<CarXiParam>, Unit>) {
        ApiClient.getInstance().getBrand2(type, pid)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<ArrayList<CarXiParam>>>() {
                    override fun onSuccess(t: BaseResp<ArrayList<CarXiParam>>) {
                        t.data?.apply {
                            kFunction1(type, this)
                        }
                    }

                    override fun onError(ex: ApiException) {

                    }

                })
    }


    //获取DMS车系
    fun getDMSseries(type: String, pid: String, kFunction1: KFunction2<@ParameterName(name = "type") String, @ParameterName(name = "list") List<Product>, Unit>) {
        ApiClient.getInstance().getDmsProducts(type.toInt(),pid)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<Product>>>() {
                    override fun onSuccess(t: BaseResp<List<Product>>) {
                        t.data?.apply {
                            kFunction1(type,this)
                        }
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }

    //获取试驾车系
    fun getDriveseries(stime: String,level:String,pid:String ,kFunction1: KFunction1<@ParameterName(name = "list") List<Product>, Unit>) {
        ApiClient.getInstance().getDriveseries(stime,level,pid)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<Product>>>() {
                    override fun onSuccess(t: BaseResp<List<Product>>) {
                        t.data?.apply {
                            kFunction1(this)
                        }
                    }
                    override fun onError(ex: ApiException) {

                    }
                })
    }

}